package com.ruoyi.common.config.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @JsonSerialize(using = LongToStringSerializer.class)  // 序列化时转换为字符串
 * @author huixh
 */
public class LongToStringSerializer extends JsonSerializer<Long> {
        @Override
        public void serialize(Long value, JsonGenerator jsonGenerator, SerializerProvider serializers) throws IOException {
            if (value != null) {
                jsonGenerator.writeString(value.toString());  // 将 Long 转换为字符串
            } else {
                jsonGenerator.writeNull();  // 处理 null 情况
            }
        }
}
